﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GenericLibrariesToolKit;
using Utils;

namespace Model
{
    /// <summary>
    /// 新闻实体
    /// </summary>
    public class News
    {
        /*新闻ID*/
        public string NewsId { get; set; }
        /*新闻发表者ID*/
        public string NewsPosterId { get; set; }
        /*新闻标题*/
        public string NewsTitle { get; set; }
        /*关键字*/
        public string NewsKey { get; set; }
        /*新闻内容*/
        public string NewsContent { get; set; }
        /*发表日期*/
        private string newsDate = DateTimeUtil.GetDateTime();
        public string NewsDate
        {
            get { return newsDate; }
            set { newsDate = value; }
        }

        /// <summary>
        /// 应用程序启动时，实体管理器将会调用此方法进行初始化。
        /// </summary>
        public void Intialization()
        {
            //声明一个实体实体对象
            Entity entity = new Entity();

            //指定该实体对应数据库中的表名
            entity.TableName = "T_NEWS";
            //指定该实体的标识符
            entity.EntityId = "NewsId";
            //指定主键生成策略
            entity.Generator = GenericLibrariesToolKit.Enumeration.PKGenerationStrategy.GUID;
            ///实体关系映射字典
            ///key:实体属性名称，value:对应的数据库中表的字段名
            Dictionary<string, string> dictionary = new Dictionary<string, string>();


            dictionary.Add("NewsId", "NEWS_ID");
            dictionary.Add("NewsPosterId", "NEWS_POSTER_ID");
            dictionary.Add("NewsTitle", "NEWS_TITLE");
            dictionary.Add("NewsKey", "NEWS_KEY");
            dictionary.Add("NewsContent", "NEWS_CONTENT");
            dictionary.Add("NewsDate", "NEWS_DATE");

            //赋值
            entity.ORMDictionary = dictionary;

            //将实体加入实体管理器，
            EntityManager.GetInsatnce().AddEntity("Model.News", entity);
        }
    }
}
